class WordDictionary
{
public:
    WordDictionary()
    {}

    void addWord(string word)
    {
        strIndexMap[word]++;
    }

    bool search(string word)
    {
        if (strIndexMap.count(word))
        {
            return true;
        }
        else
        {
            for (auto& [x, y] : strIndexMap)
            {
                int i = 0;
                if (dfs(x, word, i)) return true;
            }
            return false;
        }
    }
    bool dfs(const string& x, string& word, int i)
    {
        if (x.size() != word.size()) return false;
        if (i == x.size()) return true;
        if ((x[i] == '.' || word[i] == '.') || x[i] == word[i])
        {
            ++i;
        }
        else return  false;
        auto ret = dfs(x, word, i);
        return ret;
    }
private:
    unordered_map<string, int> strIndexMap;
};


/*
 * Your WordDictionary object will be instantiated and called as such:
 * WordDictionary* obj = new WordDictionary();
 * obj->addWord(word);
 * bool param_2 = obj->search(word);
 */